package com.region.plugin.proxy.jdk;

import com.region.plugin.Interceptor;
import com.region.plugin.proxy.AbstractRealProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author 26225
 * @date 2024/9/7 13:35
 * @description
 */
public class JdkRealProxy extends AbstractRealProxy implements InvocationHandler {

    public JdkRealProxy(Object target, Interceptor interceptor) {
        super(target, interceptor);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (Object.class.equals(method.getDeclaringClass())) {
            // If it's a method of the object class just run it
            return method.invoke(this, args);
        } else {
            return executeProceed(interceptor, new JdkProceedPoint(target, args, method));
        }
    }
}
